package org.leon.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.leon.mybatis.domain.User;

import java.util.List;

/**
 * Created by HuGuodong on 2017/5/2.
 * UserAnnotationMapper Interface
 */
public interface UserAnnotationMapper {

    @Select("SELECT * FROM mybatis_user WHERE id = #{id}")
    User selectUserById(Integer id);

    @Insert("INSERT INTO mybatis_user(name,sex,age) VALUES (#{name}, #{sex}, #{age})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int saveUser(User u);

    @Delete("DELETE FROM mybatis_user WHERE id = #{id}")
    int removeUser(@Param("id") Integer id);

    @Update("UPDATE mybatis_user SET name=#{name}, sex=#{sex}, age=#{age} " +
            "WHERE id=#{id}")
    void modifyUser(User u);


    @Select("SELECT * FROM mybatis_user")
    List<User> findAllUser();

}
